package org.jflame.web.spring.aop;

import org.jflame.context.spring.aop.KeyExprParser;
import org.jflame.web.spring.SpringWebUtils;

import java.lang.reflect.Method;

import jakarta.servlet.http.HttpServletRequest;

public class RequestUrlKeyParser implements KeyExprParser {

    @Override
    public boolean support(String keyExpression) {
        return "@url".equals(keyExpression);
    }

    @Override
    public String parse(final String key, final Method method, final Object[] methodArgs) {
        HttpServletRequest request = SpringWebUtils.getRequest();
        String url = request.getPathInfo();
        if (request.getPathInfo() != null) {
            url += request.getPathInfo();
        }
        return url;
    }

}
